import sympy as sp

# 定义符号变量
x = sp.symbols('x')
pi = sp.pi

# 定义体积函数
V = x**2 * (60 - x) / (4 * pi)

# 求导
V_prime = sp.diff(V, x)
print("体积函数的一阶导数:", V_prime)

# 求临界点
critical_points = sp.solve(V_prime, x)
print("临界点:", critical_points)

# 过滤合理临界点
valid_points = [point for point in critical_points if 0 < point < 60]
print("合理临界点:", valid_points)

# 计算体积最大值
if valid_points:
    max_point = valid_points[0]
    max_volume = V.subs(x, max_point)
    print(f"当x={max_point}cm时，圆柱体体积最大，最大体积为{max_volume.evalf()}cm³")